<%--
  Created by IntelliJ IDEA.
  User: c
  Date: 2018/8/23
  Time: 9:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>修改预约记录</title>
    <link rel="stylesheet" href="/frame/layui/css/layui.css">
    <link rel="stylesheet" href="/frame/static/css/style.css">
</head>
<body class="body">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>修改预约记录</legend>
</fieldset>
<form class="layui-form">
    <input type="text" id="resId" name="resId" hidden="hidden">
    <div class="layui-form-item">
        <label class="layui-form-label">客户姓名</label>
        <div class="layui-input-inline">
            <input type="text" id="resName" name="resName" lay-verify="required" placeholder="请输入客户姓名" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">客户性别</label>
        <div class="layui-input-block">
            <input type="radio" name="resSex" value="男" title="男" checked="">
            <input type="radio" name="resSex" value="女" title="女">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">预约时间</label>
            <div class="layui-input-inline">
                <input type="text" name="resDate" id="resDate" lay-verify="datetime" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">车牌号码</label>
        <div class="layui-input-inline">
            <input type="text" id="resDrand" name="resDrand" lay-verify="required" placeholder="请输入车牌号码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">手机号码</label>
            <div class="layui-input-inline">
                <input type="tel" id="resPhone" name="resPhone" lay-verify="phone" placeholder="请输入手机号码" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">服务类型</label>
            <div class="layui-input-inline">
                <select id="serId" name="serId" lay-verify="required">
                    <option value="">请选择类型</option>
                    <option value="1">1</option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">预约车型</label>
        <div class="layui-input-inline">
            <input type="text" id="resCarmodel" name="resCarmodel" lay-verify="required" placeholder="请输入预约车型" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">修改</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
<script src="../js/jquery.js"></script>
<script src="../frame/layui/layui.js" charset="utf-8"></script>
<script src="../js/dateToString.js"></script>
<script>
    $(function () {
        // $.ajax({
        //     url: "/reservationrecord/queryById",
        //     type: "POST",
        //     dataType:"json",
        //     async:false,
        //     data: {appid:appid},
        //     success: function(data){
        //
        //     }
        // });


        // 获取编号
        var resid=window.location.search.slice(window.location.search.lastIndexOf("?")+1);
        // 给隐藏框赋值
        $("#resId").val(resid);
        // 加载数据
        $.ajax({
            url: "/ReservationRecord/queryById",
            type: "POST",
            dataType:"json",
            async:false,
            data: {resid:resid},
            success: function(data){
                console.log(data);
                // 赋值
                $("#resName").val(data.data.resname);
                var sexs = document.getElementsByName("resSex");
                for(var i = 0;i<sexs.length;i++){
                    if(sexs[i].value==data.data.ressex){
                        sexs[i].checked='checked';
                    }
                }
                $("#resDate").val(dateToStr(data.data.resdate));
                $("#resDrand").val(data.data.resdrand);
                $("#resPhone").val(data.data.resphone);
                $("#serId").val(data.data.serviceLarge.serid);
                $("#resCarmodel").val(data.data.rescarmodel);
            }
        });
    });
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#resDate',
            type:'datetime'
        });

        //监听提交
        form.on('submit(demo1)', function(data){
            update(data);
            return false;
        });
    });
    // 修改数据
    function update(data){
        // 获取需要的值
        var resId = data.field.resId;
        var resName = data.field.resName;
        var resSex = data.field.resSex;
        var resDate = data.field.resDate;
        resDate = new Date(resDate);
        var resDrand = data.field.resDrand;
        var resPhone = data.field.resPhone;
        var serId = data.field.serId;
        serId = parseInt(serId);
        var resCarmodel = data.field.resCarmodel;
        $.ajax({
            url: "/ReservationRecord/mod",
            type: "POST",
            dataType:"json",
            data: {
                resid:resId,
                resname:resName,
                ressex:resSex,
                resdate:resDate,
                resdrand:resDrand,
                resphone:resPhone,
                "serviceLarge.serid":serId,
                rescarmodel:resCarmodel
            },
            success: function(data){
                if(data.success){
                    window.location.href ="reservationRecordList.jsp";
                }else {
                    layer.msg(data.message);
                }
            }
        });
    }
</script>
</html>